home *** CD-ROM | disk | FTP | other *** search
/ Macwelt 4 / Macwelt DVD 4.cdr / Entwickler / Mac-OS / oxygen / samples / docbook / xsl / html / math.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-09-09  |  10.8 KB  |  292 lines  |  [□□□□/□□□□]

  1. math.xsl( π¢tÚπ¢tÚÅÅ6u<?xml version='1.0'?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3.                 version='1.0'>
  4.  
  5. <!-- ********************************************************************
  6.      $Id: math.xsl,v 1.1 2002/05/29 09:55:49 dan Exp $
  7.      ********************************************************************
  8.  
  9.      This file is part of the XSL DocBook Stylesheet distribution.
  10.      See ../README or http://nwalsh.com/docbook/xsl/ for copyright
  11.      and other information.
  12.  
  13.      ******************************************************************** -->
  14.  
  15. <xsl:template match="inlineequation">
  16.   <xsl:apply-templates/>
  17. </xsl:template>
  18.  
  19. <xsl:template match="alt">
  20. </xsl:template>
  21.  
  22. <!-- Support for TeX math in alt -->
  23.  
  24. <xsl:template match="*" mode="collect.tex.math">
  25.   <xsl:call-template name="write.text.chunk">
  26.     <xsl:with-param name="filename" select="$tex.math.file"/>
  27.     <xsl:with-param name="method" select="'text'"/>
  28.     <xsl:with-param name="content">
  29.       <xsl:choose>
  30.         <xsl:when test="$tex.math.in.alt = 'plain'">
  31.           <xsl:call-template name="tex.math.plain.head"/>
  32.           <xsl:apply-templates select="." mode="collect.tex.math.plain"/>
  33.           <xsl:call-template name="tex.math.plain.tail"/>
  34.         </xsl:when>
  35.         <xsl:when test="$tex.math.in.alt = 'latex'">
  36.           <xsl:call-template name="tex.math.latex.head"/>
  37.           <xsl:apply-templates select="." mode="collect.tex.math.latex"/>
  38.           <xsl:call-template name="tex.math.latex.tail"/>
  39.         </xsl:when>
  40.         <xsl:otherwise>
  41.           <xsl:message>
  42.             Unsupported TeX math notation: 
  43.             <xsl:value-of select="$tex.math.in.alt"/>
  44.           </xsl:message>
  45.         </xsl:otherwise>
  46.       </xsl:choose>
  47.     </xsl:with-param>
  48.     <xsl:with-param name="encoding" select="$default.encoding"/>
  49.   </xsl:call-template>
  50. </xsl:template>
  51.  
  52. <!-- PlainTeX -->
  53.  
  54. <xsl:template name="tex.math.plain.head">
  55.   <xsl:text>\nopagenumbers  </xsl:text>
  56. </xsl:template>
  57.  
  58. <xsl:template name="tex.math.plain.tail">
  59.   <xsl:text>\bye  </xsl:text>
  60. </xsl:template>
  61.  
  62. <xsl:template match="inlineequation" mode="collect.tex.math.plain">
  63.   <xsl:variable name="filename">
  64.     <xsl:choose>
  65.       <xsl:when test="graphic">
  66.         <xsl:call-template name="mediaobject.filename">
  67.           <xsl:with-param name="object" select="graphic"/>
  68.         </xsl:call-template>
  69.       </xsl:when>
  70.       <xsl:otherwise>
  71.         <xsl:call-template name="select.mediaobject.filename">
  72.           <xsl:with-param name="olist" select="inlinemediaobject/*"/>
  73.         </xsl:call-template>
  74.       </xsl:otherwise>
  75.     </xsl:choose>
  76.   </xsl:variable>
  77.   <xsl:variable name="output.delims">
  78.     <xsl:call-template name="tex.math.output.delims"/>
  79.   </xsl:variable>
  80.   <xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/>
  81.   <xsl:if test="$tex">
  82.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  83.     <xsl:value-of select="$filename"/>
  84.     <xsl:text>}  </xsl:text>
  85.     <xsl:if test="$output.delims != 0">
  86.       <xsl:text>$</xsl:text>
  87.     </xsl:if>
  88.     <xsl:value-of select="$tex"/>
  89.     <xsl:if test="$output.delims != 0">
  90.       <xsl:text>$  </xsl:text>
  91.     </xsl:if>
  92.     <xsl:text>\vfill\eject  </xsl:text>
  93.   </xsl:if>
  94. </xsl:template>
  95.  
  96. <xsl:template match="equation|informalequation" mode="collect.tex.math.plain">
  97.   <xsl:variable name="filename">
  98.     <xsl:choose>
  99.       <xsl:when test="graphic">
  100.         <xsl:call-template name="mediaobject.filename">
  101.           <xsl:with-param name="object" select="graphic"/>
  102.         </xsl:call-template>
  103.       </xsl:when>
  104.       <xsl:otherwise>
  105.         <xsl:call-template name="select.mediaobject.filename">
  106.           <xsl:with-param name="olist" select="mediaobject/*"/>
  107.         </xsl:call-template>
  108.       </xsl:otherwise>
  109.     </xsl:choose>
  110.   </xsl:variable>
  111.   <xsl:variable name="output.delims">
  112.     <xsl:call-template name="tex.math.output.delims"/>
  113.   </xsl:variable>
  114.   <xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/>
  115.   <xsl:if test="$tex">
  116.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  117.     <xsl:value-of select="$filename"/>
  118.     <xsl:text>}  </xsl:text>
  119.     <xsl:if test="$output.delims != 0">
  120.       <xsl:text>$$</xsl:text>
  121.     </xsl:if>
  122.     <xsl:value-of select="$tex"/>
  123.     <xsl:if test="$output.delims != 0">
  124.       <xsl:text>$$  </xsl:text>
  125.     </xsl:if>
  126.     <xsl:text>\vfill\eject  </xsl:text>
  127.   </xsl:if>
  128. </xsl:template>
  129.  
  130. <xsl:template match="text()" mode="collect.tex.math.plain"/>
  131.  
  132. <!-- LaTeX -->
  133.  
  134. <xsl:template name="tex.math.latex.head">
  135.   <xsl:text>\documentclass{article}  </xsl:text>
  136.   <xsl:text>\pagestyle{empty}  </xsl:text>
  137.   <xsl:text>\begin{document}  </xsl:text>
  138. </xsl:template>
  139.  
  140. <xsl:template name="tex.math.latex.tail">
  141.   <xsl:text>\end{document}  </xsl:text>
  142. </xsl:template>
  143.  
  144. <xsl:template match="inlineequation" mode="collect.tex.math.latex">
  145.   <xsl:variable name="filename">
  146.     <xsl:choose>
  147.       <xsl:when test="graphic">
  148.         <xsl:call-template name="mediaobject.filename">
  149.           <xsl:with-param name="object" select="graphic"/>
  150.         </xsl:call-template>
  151.       </xsl:when>
  152.       <xsl:otherwise>
  153.         <xsl:call-template name="select.mediaobject.filename">
  154.           <xsl:with-param name="olist" select="inlinemediaobject/*"/>
  155.         </xsl:call-template>
  156.       </xsl:otherwise>
  157.     </xsl:choose>
  158.   </xsl:variable>
  159.   <xsl:variable name="output.delims">
  160.     <xsl:call-template name="tex.math.output.delims"/>
  161.   </xsl:variable>
  162.   <xsl:variable name="tex" select="alt[@role='tex'] | inlinemediaobject/textobject[@role='tex']"/>
  163.   <xsl:if test="$tex">
  164.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  165.     <xsl:value-of select="$filename"/>
  166.     <xsl:text>}  </xsl:text>
  167.     <xsl:if test="$output.delims != 0">  
  168.       <xsl:text>$</xsl:text>
  169.     </xsl:if>
  170.     <xsl:value-of select="$tex"/>
  171.     <xsl:if test="$output.delims != 0">  
  172.       <xsl:text>$  </xsl:text>
  173.     </xsl:if>
  174.     <xsl:text>\newpage  </xsl:text>
  175.   </xsl:if>
  176. </xsl:template>
  177.  
  178. <xsl:template match="equation|informalequation" mode="collect.tex.math.latex">
  179.   <xsl:variable name="filename">
  180.     <xsl:choose>
  181.       <xsl:when test="graphic">
  182.         <xsl:call-template name="mediaobject.filename">
  183.           <xsl:with-param name="object" select="graphic"/>
  184.         </xsl:call-template>
  185.       </xsl:when>
  186.       <xsl:otherwise>
  187.         <xsl:call-template name="select.mediaobject.filename">
  188.           <xsl:with-param name="olist" select="mediaobject/*"/>
  189.         </xsl:call-template>
  190.       </xsl:otherwise>
  191.     </xsl:choose>
  192.   </xsl:variable>
  193.   <xsl:variable name="output.delims">
  194.     <xsl:call-template name="tex.math.output.delims"/>
  195.   </xsl:variable>
  196.   <xsl:variable name="tex" select="alt[@role='tex'] | mediaobject/textobject[@role='tex']"/>
  197.   <xsl:if test="$tex">
  198.     <xsl:text>\special{dvi2bitmap outputfile </xsl:text>
  199.     <xsl:value-of select="$filename"/>
  200.     <xsl:text>}  </xsl:text>
  201.     <xsl:if test="$output.delims != 0">
  202.       <xsl:text>$$</xsl:text>
  203.     </xsl:if>
  204.     <xsl:value-of select="$tex"/>
  205.     <xsl:if test="$output.delims != 0">
  206.       <xsl:text>$$  </xsl:text>
  207.     </xsl:if>
  208.     <xsl:text>\newpage  </xsl:text>
  209.   </xsl:if>
  210. </xsl:template>
  211.  
  212. <xsl:template match="text()" mode="collect.tex.math.latex"/>
  213.  
  214. <!-- Extracting image filename from mediaobject and graphic elements -->
  215.  
  216. <xsl:template name="select.mediaobject.filename">
  217.   <xsl:param name="olist"
  218.              select="imageobject|imageobjectco
  219.                      |videoobject|audioobject|textobject"/>
  220.   <xsl:param name="count">1</xsl:param>
  221.  
  222.   <xsl:if test="$count <= count($olist)">
  223.     <xsl:variable name="object" select="$olist[position()=$count]"/>
  224.  
  225.     <xsl:variable name="useobject">
  226.       <xsl:choose>
  227.     <!-- The phrase is never used -->
  228.         <xsl:when test="name($object)='textobject' and $object/phrase">
  229.           <xsl:text>0</xsl:text>
  230.         </xsl:when>
  231.     <!-- The first textobject is not a reasonable fallback for equation image -->
  232.         <xsl:when test="name($object)='textobject'">
  233.           <xsl:text>0</xsl:text>
  234.         </xsl:when>
  235.     <!-- If there's only one object, use it -->
  236.     <xsl:when test="$count = 1 and count($olist) = 1">
  237.       <xsl:text>1</xsl:text>
  238.     </xsl:when>
  239.     <!-- Otherwise, see if this one is a useable graphic -->
  240.         <xsl:otherwise>
  241.           <xsl:choose>
  242.             <!-- peek inside imageobjectco to simplify the test -->
  243.             <xsl:when test="local-name($object) = 'imageobjectco'">
  244.               <xsl:call-template name="is.acceptable.mediaobject">
  245.                 <xsl:with-param name="object" select="$object/imageobject"/>
  246.               </xsl:call-template>
  247.             </xsl:when>
  248.             <xsl:otherwise>
  249.               <xsl:call-template name="is.acceptable.mediaobject">
  250.                 <xsl:with-param name="object" select="$object"/>
  251.               </xsl:call-template>
  252.             </xsl:otherwise>
  253.           </xsl:choose>
  254.         </xsl:otherwise>
  255.       </xsl:choose>
  256.     </xsl:variable>
  257.  
  258.     <xsl:choose>
  259.       <xsl:when test="$useobject='1'">
  260.         <xsl:call-template name="mediaobject.filename">
  261.           <xsl:with-param name="object" select="$object"/>
  262.         </xsl:call-template>
  263.       </xsl:when>
  264.       <xsl:otherwise>
  265.         <xsl:call-template name="select.mediaobject">
  266.           <xsl:with-param name="olist" select="$olist"/>
  267.           <xsl:with-param name="count" select="$count + 1"/>
  268.         </xsl:call-template>
  269.       </xsl:otherwise>
  270.     </xsl:choose>
  271.   </xsl:if>
  272. </xsl:template>
  273.  
  274. <xsl:template name="tex.math.output.delims">
  275.   <xsl:variable name="pi.delims">
  276.     <xsl:call-template name="pi-attribute">
  277.       <xsl:with-param name="pis" select=".//processing-instruction('dbtex')"/>
  278.       <xsl:with-param name="attribute" select="'delims'"/>
  279.     </xsl:call-template>
  280.   </xsl:variable>
  281.   <xsl:variable name="result">
  282.     <xsl:choose>
  283.       <xsl:when test="$pi.delims = 'no'">0</xsl:when>
  284.       <xsl:when test="$pi.delims = '' and $tex.math.delims = 0">0</xsl:when>
  285.       <xsl:otherwise>1</xsl:otherwise>
  286.     </xsl:choose>
  287.   </xsl:variable>
  288.   <xsl:value-of select="$result"/>
  289. </xsl:template>
  290.  
  291. </xsl:stylesheet>
  292. This resource fork intentionally left blank   ˇˇ